﻿var count = 0;
jQuery(document).ready(function() {
    jQuery("#GridView1 :checkbox").attr("checked", false);
    jQuery("#Button1").attr("disabled", "disabled");
    jQuery("#Button2").attr("disabled", "disabled");
    jQuery("#Button3").attr("disabled", "disabled");
    jQuery("#btnLockUser").attr("disabled", "disabled");
    jQuery("#btnUnlock").attr("disabled", "disabled");
    if (jQuery("#DropDownList1 option:selected").val() == "禁用") {
        jQuery("#Button2").css("display", "none");
        jQuery("#btnLockUser").css("display", "none");
        jQuery("#btnUnlock").css("display", "block");
    }
    if (jQuery(":checkbox").size() == 2) {
        jQuery("#GridView1").attr("border", "0px");
        jQuery("#GridView1").css({ "border-width": "0px" });
        jQuery("#GridView1").css("display", "none");
        jQuery("#tabA").css("display", "none");
    }
    jQuery("#CheckBox2").attr("checked", false);
    if (!jQuery("#chkIsLocked").attr("checked")) {
        jQuery("#btnUnlock").css("display", "none");
    }
    else {
        jQuery("#btnLockUser").css("display", "none");
        jQuery("#Button2").css("display", "none");
    }
    jQuery("#GridView1 :checkbox").click(function() {
        if (jQuery(this).attr("checked")) {
            count++;
            if (count == jQuery("#GridView1 :checkbox").length) {
                jQuery("#CheckBox2").attr("checked", true);
            }
            jQuery("#Button1").removeAttr("disabled");
            jQuery("#Button2").removeAttr("disabled");
            jQuery("#Button3").attr("disabled", "disabled");
            jQuery("#btnLockUser").removeAttr("disabled");
            jQuery("#btnUnlock").removeAttr("disabled");
        }
        else {
            jQuery("#CheckBox2").attr("checked", false);
            if (count > 0) {
                count--;
            }
            if (count == 0) {
                jQuery("#Button1").attr("disabled", "disabled");
                jQuery("#Button2").attr("disabled", "disabled");
                jQuery("#btnLockUser").attr("disabled", "disabled");
                jQuery("#btnUnlock").attr("disabled", "disabled");
            }
        }
        if (count == 1) {
            jQuery("#Button3").removeAttr("disabled");
        }
        else {
            jQuery("#Button3").attr("disabled", "disabled");
        }
    });
    jQuery("#CheckBox2").click(function() {
        if (jQuery(this).attr("checked")) {
            jQuery("#GridView1 :checkbox").attr("checked", true);
            count = jQuery("#GridView1 :checkbox").length;
            jQuery("#Button1").removeAttr("disabled");
            jQuery("#Button2").removeAttr("disabled");
            jQuery("#btnLockUser").removeAttr("disabled");
            jQuery("#btnUnlock").removeAttr("disabled");
        }
        else {
            jQuery("#GridView1 :checkbox").attr("checked", false);
            count = 0;
            jQuery("#Button1").attr("disabled", "disabled");
            jQuery("#Button2").attr("disabled", "disabled");
            jQuery("#Button3").attr("disabled", "disabled");
            jQuery("#btnLockUser").attr("disabled", "disabled");
            jQuery("#btnUnlock").attr("disabled", "disabled");
        }
    });
    jQuery("#Button3").click(function() {
        var val = $.trim(jQuery("#GridView1 :checked").parents("tr").eq(0).find("td.hideColumn").text());
        location.href = "updateuser1.aspx?id=" + val;
    });
});